package com.mijie.homi.dao.user;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.common.domain.user.Privacy;

@Repository
public class PrivacyDao extends IBatisDao {

	public int updatePrivacy(Privacy privacy){
		return this.update("updatePrivacy", privacy);
	}
	
	public int addPrivacy(Privacy privacy){
		return this.insert("addPrivacy", privacy);
	}
	
	public Privacy getPrivacy(int id){
		return this.selectOne("getPrivacy", id);
	}
	
	public int acceptPrivacyApply(int applicant,int master,String module){
		return this.insert("acceptPrivacyApply", genPermission(applicant,master,module));
	}
	
	public boolean haveSpecialPermission(int applicant,int master,String module){
		String p = this.selectStr("haveSpecialPermission",genPermission(applicant,master,module));
		return p!=null;
	}
	
	private String genPermission(int applicant,int master,String module){
		StringBuilder permissions = new StringBuilder();
		permissions.append(master).append("_").append(module).append("_").append(applicant);
		return permissions.toString();
	}
}
